package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.cabinetKeyPojo;
import com.example.service.cabinetKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class cabinetKeyController {

    @Autowired
    private cabinetKeyService cabinetKeyService;

    // 查询所有柜门钥匙信息
    @PostMapping("/queryCabinetKey")
    public Result queryCabinetKey() {
        // 调用服务层查询所有柜门钥匙信息的方法
        List<cabinetKeyPojo> cabinetKeyPojoList = cabinetKeyService.queryAll();
        System.out.println("cabinet查询成功");
        return Result.success(cabinetKeyPojoList);  // 返回查询结果
    }

    // 添加新的柜门钥匙
    @PostMapping("/addCabinetKey")
    public Result addCabinetKey(@RequestBody cabinetKeyPojo cabinetKeyPojo) {
        System.out.println(cabinetKeyPojo);
        cabinetKeyService.insertOne(cabinetKeyPojo);  // 调用服务层插入方法
        System.out.println("cabinet添加成功");
        return Result.success();  // 返回成功响应
    }

    // 编辑柜门钥匙信息
    @PostMapping("/editCabinetKey")
    public Result editCabinetKey(@RequestBody cabinetKeyPojo cabinetKeyPojo) {
        cabinetKeyService.editCabinetKey(cabinetKeyPojo);  // 调用服务层编辑方法
        System.out.println("cabinet修改成功");
        return Result.success("cabinet修改成功");  // 返回成功响应
    }
}
